package com.dailyblue.java.cloud.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@EnableDiscoveryClient
public class NacosConfigApplication {
    public static void main(String[] args) throws Exception{
        // 当当前项目运行时，获取配置文件信息
        ConfigurableApplicationContext applicationContext = SpringApplication.run(NacosConfigApplication.class, args);
        while (true) {
            // 获取配置
            String id = applicationContext.getEnvironment().getProperty("student.id");
            String name = applicationContext.getEnvironment().getProperty("student.name");
            String age = applicationContext.getEnvironment().getProperty("student.age");
            System.out.println(id);
            System.out.println(name);
            System.out.println(age);
            TimeUnit.SECONDS.sleep(1);
        }
    }
}
